package com.yida.gwj.report.controller;

import com.yida.common.core.web.controller.BaseController;
import com.yida.common.core.web.domain.AjaxResult;
import com.yida.common.core.web.page.TableDataInfo;
import com.yida.common.log.annotation.Log;
import com.yida.common.log.enums.BusinessType;
import com.yida.gwj.report.domain.request.GwjCalculateRateRequest;
import com.yida.gwj.report.domain.request.GwjReportYearBenifitRequest;
import com.yida.gwj.report.domain.request.GwjSettleRateRequest;
import com.yida.gwj.report.service.IGwjCalculateRateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @Author: PPV
 * @Date: 2023-03-08
 */
@RestController
@RequestMapping("/calculate")
@Api(tags = "本年积数计息")
public class GwjCalculateRateController extends BaseController {

    @Resource
    private IGwjCalculateRateService calculateRateService;

    @PostMapping
    @ApiOperation("新增年增值收益")
    public AjaxResult save(@RequestBody @Valid GwjReportYearBenifitRequest request) {
        calculateRateService.save(request);
        return AjaxResult.success();
    }

    @PutMapping
    @ApiOperation("更新年增值收益")
    public AjaxResult update(@RequestBody @Valid GwjReportYearBenifitRequest request) {
        calculateRateService.update(request);
        return AjaxResult.success();

    }

    @DeleteMapping("/{benefitIds}")
    @ApiOperation("批量删除年增值收益")
    public AjaxResult del(@PathVariable("benefitIds") Long[] benefitIds) {
        calculateRateService.delBatch(benefitIds);
        return AjaxResult.success();
    }

    @GetMapping("/list")
    @ApiOperation("查询年增值收益")
    public TableDataInfo getPage(@RequestParam(required = false) String year, @RequestParam(required = false) String status) {
        return getDataTable(calculateRateService.getPage(year, status));
    }

    @PutMapping("/{benefitId}")
    @ApiOperation("确认不再修改")
    public AjaxResult confirm(@PathVariable("benefitId") Long benefitId) {
        calculateRateService.confirm(benefitId);
        return AjaxResult.success();
    }

    @PostMapping("/single")
    @ApiOperation("计息展示")
    @Log(title = "计息展示", businessType = BusinessType.OTHER, systemName = "gwj")
    public AjaxResult calculateRateShow(GwjCalculateRateRequest request) {
        return AjaxResult.success(calculateRateService.calculateRateShow(request));
    }

    @PutMapping("/settle")
    @ApiOperation("地区结息")
    public AjaxResult settleRate(GwjSettleRateRequest request) {
        calculateRateService.settleRate(request);
        return AjaxResult.success();
    }

    @PutMapping("/finish")
    @ApiOperation("息转本")
    public AjaxResult interest2Money(@RequestParam("areaId") Long areaId,@RequestParam("calculateFlag") String calculateFlag) {
        calculateRateService.interest2Money(areaId,calculateFlag);
        return AjaxResult.success();
    }


    /**
     * 地区结息-新
     * @param request 请求参数
     * @return
     */
    @PutMapping("/new/settle")
    @ApiOperation("地区结息-新")
    public AjaxResult newSettleRate(@Validated @RequestBody GwjSettleRateRequest request){
        calculateRateService.newSettleRate(request);
        return AjaxResult.success();
    }

    /**
     * 地区结息-新
     * @param request 请求参数
     * @return
     */
    @PutMapping("/new/settle/all")
    @ApiOperation("全地区结息-新")
    public AjaxResult newSettleRateAll(@Validated @RequestBody GwjSettleRateRequest request){
        request.setAreaId(null);
        calculateRateService.newSettleRateAll(request);
        return AjaxResult.success();
    }
}
